package simulator;

import java.io.*;
import java.util.*;
import configuration.Configuration;

/**
 * The simulator test file contains the main method to run the software
 * simulator
 * 
 * @author Nodirjon Siddikov
 */
public class SimulatorTest {
	public static void main(String[] args) throws Exception {
		// the path of the configuration file has to be updated in each system
		String configFilePath = "Config.txt";//"I:\\rit\\thesis\\code\\simulator\\configuration\\Config.txt";
		Configuration.parse(configFilePath);
		int traceFile = Configuration.trace;
		// the path of the trace file has to be updated in each system
		String traceFilePath = "Trace"//"I:\\rit\\thesis\\code\\simulator\\configuration\\Trace"
				+ traceFile + ".txt";
		// generateTrace(traceFilePath);
		System.out.println("Using trace file: " + traceFile);
		Simulator simTest = new Simulator();
		simTest.runSimulator(traceFilePath);
	}

	// generate the traces of block
	// the trace consists of IDs of blocks
	public static void generateTrace(String traceFileName) {
		// random function
		Random prng = new Random();
		int noOfRequests = Configuration.noOfReadRequests;
		try { // Create file
			FileWriter fstream = new FileWriter(traceFileName);
			PrintWriter out = new PrintWriter(fstream);
			// generate disk block traces
			for (int i = 0; i < noOfRequests; i++) {
				out.println(prng.nextInt(Configuration.noOfBlocks));
			}
			// Close the output stream
			out.close();
		} catch (Exception e) {
			System.err.println("Error: " + e.getMessage());
		}
	}
}